package com.avengers.core.kit;

import java.util.Collections;
import java.util.List;

/**
 * @author yu.wang
 * @since 1/20/21 3:25 PM
 **/
public class CollectionsKit {
    public static boolean isSameList(List<String> list1, List<String> list2) {
        return isSameList(list1, list2, false);
    }

    public static boolean isSameList(List<String> list1, List<String> list2, boolean ignoreCase) {
        if (null == list1 && null == list2) {
            return true;
        }
        if (null == list1 || null == list2) {
            return false;
        }
        if (list1.size() != list2.size()) {
            return false;
        }
        Collections.sort(list1);
        Collections.sort(list2);
        for (int i = 0; i < list1.size(); i++) {
            String a = list1.get(i);
            String b = list2.get(i);
            if (StringKit.isBlank(a) && StringKit.isBlank(b)) {
                continue;
            } else if (StringKit.isBlank(a) || StringKit.isBlank(b)) {
                return false;
            }
            if (ignoreCase) {
                if (!a.equalsIgnoreCase(b)) {
                    return false;
                }
            } else if (!a.equals(b)) {
                return false;
            }
        }
        return true;
    }
}
